package com.example.liumuyao.recyclerviewtest_412lmy.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.liumuyao.recyclerviewtest_412lmy.adapter.tcaseAdapter;
import com.example.liumuyao.recyclerviewtest_412lmy.R;
import com.example.liumuyao.recyclerviewtest_412lmy.bean.tcaseBean;
import com.example.liumuyao.recyclerviewtest_412lmy.iface.tcaseListener;
import com.example.liumuyao.recyclerviewtest_412lmy.model.tcaseModel;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;//显示布局效果
    private tcaseAdapter tcaseAdapter;//适配器
    private List<tcaseBean> list = null;//数据源

    tcaseListener tcaseListener = new tcaseListener() {
        @Override
        public void onResponse(List<tcaseBean> beanList) {
            list = beanList;//拿到文章数据
            tcaseAdapter.setList(list);
            tcaseAdapter.notifyDataSetChanged();//通知更新
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this,"失败"+msg,Toast.LENGTH_SHORT);
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initRecyclerView();

        tcaseModel model = new tcaseModel();
        model.getResultList("article", 1, "k17vmm42ui9al6clh0lo3de2t7", tcaseListener);
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //list = getData();
        tcaseAdapter = new tcaseAdapter(this);
        tcaseAdapter.setList(list);
        recyclerView.setAdapter(tcaseAdapter);
    }
}
/*
    //自定义：获取数据源并形成list
    private List<ArticleBean> getData(){
        //定义List，赋值，返回
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        ArticleBean articleBean;
        //第一组
        articleBean = new ArticleBean();
        articleBean.setId(1);
        articleBean.setName("标题1");
        articleBean.setDescription("描述1");
        articleBean.getUpdate_time();
        articleBean.getThumb();
        list.add(articleBean);

        articleBean = new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("标题2");
        articleBean.setDescription("描述2");
        articleBean.setTime("2017-4-1");
        articleBean.setImgid(R.drawable.f2);
        list.add(articleBean);

        articleBean = new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("标题3");
        articleBean.setDescription("描述3");
        articleBean.setTime("2017-4-1");
        articleBean.setImgid(R.drawable.f3);
        list.add(articleBean);

        articleBean = new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("标题4");
        articleBean.setDescription("描述4");
        articleBean.setTime("2017-4-1");
        articleBean.setImgid(R.drawable.f4);
        list.add(articleBean);

        articleBean = new ArticleBean();
        articleBean.setArticleId(5);
        articleBean.setTitle("标题5");
        articleBean.setDescription("描述5");
        articleBean.setTime("2017-4-1");
        articleBean.setImgid(R.drawable.f5);
        list.add(articleBean);

        articleBean = new ArticleBean();
        articleBean.setArticleId(6);
        articleBean.setTitle("标题6");
        articleBean.setDescription("描述6");
        articleBean.setTime("2017-4-1");
        articleBean.setImgid(R.drawable.f6);
        list.add(articleBean);
       return list;
    }
}
*/